//
//  FPToRepayDetailCell.m
//  FinanceProject
//
//  Created by 陈显摆 on 2025/3/13.
//

#import "FPToRepayDetailCell.h"

@implementation FPToRepayDetailCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.backView.clipsToBounds = YES;
    self.backView.layer.cornerRadius = 8.f;
    
    self.borrowTimeLab.textColor = [UIColor hexColor:@"#6A6A6A"];
    self.currenTimeLa.textColor = [UIColor hexColor:@"#6A6A6A"];
    self.amountLab.textColor = [UIColor hexColor:@"#3A3A3A"];
    
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    
    self.penalLab.clipsToBounds = YES;
    self.penalLab.layer.cornerRadius = 4.f;
    self.penalLab.textColor = [UIColor hexColor:@"#F12D2D"];
    self.penalLab.layer.borderColor = [UIColor hexColor:@"#F12D2D"].CGColor;
    self.penalLab.layer.borderWidth = 1.f;
}


- (void)analysisBorrowTime:(NSString *)time {
    
    NSString *text = [NSString stringWithFormat:@"借款日 | %@",time];
    
    NSRange range = [text rangeOfString:time];
    
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:text];
    
    [NSString stringToAttribute:attr color:UIColor.blackColor range:range];
    
    self.borrowTimeLab.attributedText = attr;
}

- (void)analysisRepayCurrenLimit:(NSString *)currenLimit totalLimit:(NSString *)totalLimit {
    
    NSString *text;
    
    // 借款期限（期数）0.3个月,1.6个月,2.9个月,3.12个月,4.24个月
    switch (totalLimit.integerValue) {
        case 0:
            text = @"3";
            break;
            
        case 1:
            text = @"6";
            break;
            
        case 2:
            text = @"9";
            break;
            
        case 3:
            text = @"12";
            break;
            
        case 4:
            text = @"24";
            break;
            
        default:
            break;
    }
    
    
    NSString *finalText = [NSString stringWithFormat:@"本期应还(%@/%@)",currenLimit , text];
    
    self.currenTimeLa.text = finalText;
}

- (void)analysisAmount:(NSString *)amount {
    
    NSString *text = [NSString stringWithFormat:@"￥%.2f",amount.floatValue];
    
    NSRange range = [text rangeOfString:@"￥"];
    
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:text];
    
    [NSString stringToAttribute:attr font:[UIFont systemFontOfSize:16.f weight:(UIFontWeightMedium)] range:range];
    
    self.amountLab.attributedText = attr;
}

- (void)analysisPenal:(BOOL)isPenal days:(NSString *)days {
    
    if (isPenal) {
        
        self.penalLab.hidden = NO;
        
        NSString *text = [NSString stringWithFormat:@"已逾期%@天",days];
        
        self.penalLab.text = text;
        
        self.penalWidth.constant = [UIView widthWithString:text labelHeight:19.f fontSize:12.f] + 12.f;
    }
    else {
        
        self.penalLab.hidden = YES;
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
